package kr.pe.johnkim.app.mobile.rest.dao;

import kr.pe.johnkim.app.domain.MyHistoryCategory;
import kr.pe.johnkim.app.domain.MyHistoryItem;
import kr.pe.johnkim.app.domain.MyHistoryCategoryRelation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import java.util.List;

/**
 * @author : johnkim <cale9797@gmail.com / Simple.ly Inc,>
 * @Date : 11. 12. 27
 */
public class MyHistoryCatetoryRelationDaoImpl extends SqlMapClientDaoSupport implements MyHistoryCatetoryRelationDao {
    // SLF4J Logging
	private Logger logger = LoggerFactory.getLogger(MyHistoryCatetoryRelationDaoImpl.class);
    
    /**
     * 아이템을 카테고리에 연결 한다.
     *
     * @param myHistoryCategoryRelation
     * @return True or False
     */
    public boolean registerRelation(MyHistoryCategoryRelation myHistoryCategoryRelation) {
        logger.info("registerRelation");

        boolean result = false;

        try {
            getSqlMapClientTemplate().insert("MYHISTORY_CATEGORY_RELATION.registerRelation", myHistoryCategoryRelation);
            result = true;
        } catch (Exception e) {
            result = false;
        }

        return result;
    }

    /**
     * 아이템을 카테고리에 연결을 해제 한다.
     *
     * @param myHistoryCategoryRelation
     * @return True or False
     */
    public boolean updateDeactivateRelation(MyHistoryCategoryRelation myHistoryCategoryRelation) {
        logger.info("updateDeactivateRelation");

        boolean result = false;

        try {
            getSqlMapClientTemplate().update("MYHISTORY_CATEGORY_RELATION.updateDeactivateRelation", myHistoryCategoryRelation);
            result = true;
        } catch (Exception e) {
            result = false;
        }

        return result;
    }

    /**
     * 아이템에 등록된 카테고리 목록을 가져 온다.
     *
     * @param myHistoryCategoryRelation
     * @return List<MyHistoryRelation>
     */
    public List<MyHistoryCategory> selectRelationCategoryList(MyHistoryCategoryRelation myHistoryCategoryRelation) {
        logger.info("selectRelationCategoryList");
        return this.getSqlMapClientTemplate().queryForList("MYHISTORY_CATEGORY_RELATION.selectRelationCategoryList", myHistoryCategoryRelation);
    }

    /**
     * 카테고리에 등록된 아이템 목록을 가져 온다.
     *
     * @param myHistoryCategoryRelation
     * @return List<MyHistoryItem>
     */
    public List<MyHistoryItem> selectRelationItemList(MyHistoryCategoryRelation myHistoryCategoryRelation) {
        logger.info("selectRelationItemList");
        return this.getSqlMapClientTemplate().queryForList("MYHISTORY_CATEGORY_RELATION.selectRelationItemList", myHistoryCategoryRelation);
    }
}
